<div class="layuimini-main">

	<form class="layui-form layuimini-form" action="" style="padding-top:20px;">
		
		<div class="layui-form-item">
			<label class="layui-form-label required"> 账号名 </label>
			<div class="layui-input-inline">
				<input type="text" name="account" id="account" value="" disabled="" class="layui-input layui-disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required"> 姓名 </label>
			<div class="layui-input-inline">
				<input type="text" name="name" id="name" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required"> 联系电话 </label>
			<div class="layui-input-inline">
				<input type="text" name="phone" id="phone" class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
		    <div class="layui-input-block">
		        <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"> 保存 </button>
		    </div>
		</div>
	</form>
</div>


<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/paigusu.min.js" charset="utf-8"></script>
<script>
	//引用
	layui.use(['form', 'layer'], function() {
		//初始化声明
		var $ = layui.jquery,
			form = layui.form, //将layui中的form组件对象定义成form
			layer = layui.layer;

		//渲染form表单
		form.render();
		//从数据库拿数据
		layer.ready(function(){
			$.ajax({
				url:'http://localhost:8003/sncUserLogin/'+localStorage.getItem("userId"),
				type:'get',
				async:false,
				success:function(result){
					var data=result.data;
					$("#account").val(data.count);
					$("#name").val(data.name);
					$("#phone").val(data.phone);
				}
			});
		});
		
		//监听保存按钮
		form.on('submit(saveBtn)', function (data) {
			
			layer.confirm('真的保存行么', function(index) {
				console.log(data.patientId);
				//TODO:请求后端接口进行删除操作
				//获得表单数据
					var formData = data.field;
					formData={
						'id': localStorage.getItem("userId"),
						'count': formData.count,
						'name': formData.name,
						'phone': formData.phone
					}
					console.log(formData);
					
					$.ajax({
						url : 'http://localhost:8003/sncUserLogin/upd',
						type: 'put',
						data: JSON.stringify(formData),
						contentType: "application/json;charset=UTF-8",
						success: function(result){
							console.log(result);
							//刷新页面
							//关闭确认消息框
							layer.close(index);
						},
						error:function(result){
							console.log(result);
						}
					});
				});
			
			});
			
	});
</script>
